package com.wenyang.controller;

import com.wenyang.dao.OrderDao;
import com.wenyang.entity.VO.OrderVo;
import com.wenyang.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Zx
 * @Date 2024/3/28 17:13
 * @Version 1.0
 * 订单类
 */
@RestController
@RequestMapping("/order")
@Api(value = "订单管理",tags = {"订单管理"})
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private OrderDao orderDao;

    @ApiOperation(value = "订单管理")
    @PostMapping("/listAllByPage")
    public Map<String,Object> listAllByPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize,@RequestParam(required = false) String comments){
        int startIdx = (pageNum - 1) * pageSize,size = pageSize;
        //根据分页条件查询所有订单信息
        List<OrderVo> orderVoList = orderService.listAllByPage(startIdx,size,comments);
        //查询总条数
        int total = orderDao.selectTotalWithPage();
        //创建map，并将查询出来的数据封装
        HashMap<String, Object> map = new HashMap<>();
        map.put("data",orderVoList);
        map.put("msg","执行成功");
        map.put("total",total);
        //返回map
        return map;
    }

}
